<template>
  <!-- 余额变动 -->
  <div class="parsonalDetails">
    <!-- 订单统计 -->
    <Statistics :totalMoney="totalMoney" :orderLength="orderLength"></Statistics>
    <!-- 表格部分 -->
    <div class="tableData">
      <el-table style="width: 100%;margin-bottom: 40px" :data="tableData">
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" min-width="100" label="订单号">
          <template slot-scope="scope">
            <span>{{scope.row.order_id.substring(scope.row.order_id.length - 8)}}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          min-width="120"
          :show-overflow-tooltip="true"
          label="订单说明"
          prop="sv_dwc_desc"
        ></el-table-column>
        <el-table-column align="center" label="代币" prop="sv_dwc_amount"></el-table-column>
        <el-table-column align="center" min-width="100" label="使用前代币" prop="sv_dwc_amountbefore"></el-table-column>
        <el-table-column align="center" min-width="100" label="使用后代币" prop="sv_dwc_amountafter"></el-table-column>
        <el-table-column
          align="center"
          label="时间"
          prop="sv_dwc_date"
          min-width="160"
          :formatter="dateFormat"
        ></el-table-column>
      </el-table>
    </div>
    <!-- 分页器部分 -->
    <Pagination
      :total="total"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    ></Pagination>
  </div>
</template>

<script>
import Statistics from "@/components/Statistics";
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      // 表格数据
      tableData: [],
      // 统计的总金额
      totalMoney: 0,
      // 分页器的数据
      total: 0, // 总条数
      pageIndex: 1, // 当前页
      pageSize: 10, // 每页数量
      // 每页订单数量
      orderLength: "",
      // 身份令牌
      myToken: ""
    };
  },
  components: {
    Pagination,
    Statistics
  },
  methods: {
    // 获取数据的方法
    getOrderData() {
      this.$api
        .getBalanceChangeList(this.pageIndex, this.pageSize, this.myToken)
        .then(res => {
          // console.log(res);
          this.totalMoney = 0;
          if (res.succeed) {
            const { dataList, total } = res.values;
            this.total = total;
            this.orderLength = dataList.length;
            if (dataList == null) {
              this.tableData = dataList;
              return;
            }
            this.tableData = dataList.map(v => {
              this.totalMoney += v.sv_do_price;
              return {
                ...v
              };
            });
          }
        });
    },
    // 分页器的方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrderData();
    },
    //时间格式化
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
    }
  },
  mounted() {
    // 获取令牌
    this.myToken = sessionStorage.getItem("myToken");
    // 初始化列表
    this.getOrderData();
  }
};
</script>

<style lang="less" scoped>
@deep: ~">>>";
.parsonalDetails {
  background-color: #fff;
  padding: 20px;
  .search {
    margin-bottom: 20px;
  }
  // 更改表头颜色
  .tableData @{deep} .el-table th {
    background-color: #fafafa;
    color: #252525;
    font-weight: 100;
  }
}
</style>